package com.portal.portal.config.service;

import java.util.HashSet;
import java.util.Set;

import javax.portlet.PortletMode;
import javax.servlet.ServletContext;

import com.portal.portal.config.DriverResourceConfig;
import com.portal.util.constants.ServletAttributeKeys;
import com.portal.util.exception.PortalDriverConfigurationException;

public class DriverSupportedModesServiceImpl implements DriverSupportedModesService {

  private Set<PortletMode> supportedPortletModes = new HashSet<PortletMode>();
  private DriverResourceConfig driverResourceConfig;

  public void destroy() throws PortalDriverConfigurationException {
    // TODO Auto-generated method stub

  }

  public void init(ServletContext ctx) throws PortalDriverConfigurationException {
    driverResourceConfig = (DriverResourceConfig) ctx.getAttribute(ServletAttributeKeys.DRIVER_RESOURCE_CONFIG);

    if (driverResourceConfig == null) {
      throw new PortalDriverConfigurationException("DriverSupportedModesServiceImpl");
    }

    for (String mode : driverResourceConfig.getSupportedPortletModes()) {
      supportedPortletModes.add(new PortletMode(mode));
    }
  }

  public Set<PortletMode> getSupportedPortletModes(String portletId) throws PortalDriverConfigurationException {
    return supportedPortletModes;
  }

}
